package de.gameduell.framework.facebook.app.popups {
	import fl.transitions.easing.Regular;

	import de.gameduell.facebook.service.gen.CatalogItem;
	import de.gameduell.framework.debug.Debug;
	import de.gameduell.framework.gui.animation.GDTween;
	import de.gameduell.framework.gui.button.ButtonEvent;

	import flash.display.Sprite;

	public class BuyLifeForCashPopup extends PyramidBasePopup {
		
		public function BuyLifeForCashPopup(){
			super("buyLifeForCashPopup", "buyLivesPopup", 0, true);
			
			var item:CatalogItem = controller.catalog.getItemByTitle("MPY_LIFE");
			
			localeData.setValue("livesCountToBuy", "1");
			localeData.setValue("lifePrice", String(item.price));
			
			registerButton("buyLivesButton", buyItem);
			registerButton("skipButton", hide);
			
			_position.y = layout.contentPosition.y + 10;
			
			showTween = new GDTween(sprite, "alpha", Regular.easeOut, 0, 1, 0.3, true);
			_hideTween = null;
		}

		private function buyItem(event:ButtonEvent):void {
			Debug.trace("BuyLifeForCashPopup::buyItem");
			try{
				(sprite.getChildByName("buyLivesButton") as Sprite).mouseEnabled = false;
				(sprite.getChildByName("buyLivesButton") as Sprite).mouseChildren = false;
			}catch(e:Error){
				// just in case
			}
			hide();
			var item:CatalogItem = controller.catalog.getItemByTitle("MPY_LIFE");
			controller.buyItem(item);
		}
	}
}
